package com.yisen.dasan.service.impl;

import com.yisen.dasan.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

/**
 * @AuthorList: LiuYiSen
 * @Date: 2020/10/20 11:50
 */
@Component
public class MailServiceImpl implements MailService {
    @Autowired
    private JavaMailSender mailSender;
    @Value("${spring.mail.username}")
    private String from;
    @Override
    public boolean userRegister(String key,String mail) throws MessagingException {
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
        helper.setFrom(from);// 设置发件人
        helper.setTo(mail);// 设置收件人
        helper.setSubject("金太阳用户注册");// 设置主题
        String content = "<html>\n" +
                "\t<head>\n" +
                "\t\t<meta charset=\"utf-8\">\n" +
                "\t\t<title></title>\n" +
                "\t</head>\n" +
                "\t<body>\n" +
                "\t\t<div style=\"line-height:1.7;color:#000000;font-size:14px;font-family:Arial\"><div><p style=\"margin:0;\"><span style=\"font-size: 18px;\">您正在注册金表单平台，请点击下方链接进行激活。</span><span style=\"font-size: 18px; background-color: rgb(255, 255, 255); color: rgb(221, 64, 50);\"><b>如非您本人操作请勿点击！</b></span><br /></p><p style=\"margin:0;\"><span style=\"font-size: 18px; background-color: rgb(255, 255, 255); color: rgb(221, 64, 50);\"><b><br /></b></span></p><p style=\"margin:0;\"><span style=\"font-size: 18px; background-color: rgb(255, 255, 255); color: rgb(221, 64, 50);\"><b><a href=\"http://8.129.71.245:8080/user/affirm/"+key+"\">http://8.129.71.245/user/affirm/"+key+"</a><br /></b></span></p><p style=\"margin:0;\"><span style=\"font-size: 18px; background-color: rgb(255, 255, 255); color: rgb(221, 64, 50);\"><b><br /></b></span></p><p style=\"margin:0;\"><font color=\"#dd4032\"><span style=\"font-size: 18px; color: rgb(0, 0, 0);\">感谢您的使用，祝您身体健康，万事如意！</span></font></p><br /><br /></div></div><br /><br /><span title=\"neteasefooter\"><p>&nbsp;</p></span>\n" +
                "\t</body>\n" +
                "</html>\n";
        helper.setText(content,true); // 内容

        mailSender.send(mimeMessage);
        return false;
    }
}
